/*
 * bmesh.h - reading .bmesh files
 *
 * Tab size is 4 in this file.
 */

#ifndef INCLUDED_BMESH_H
#define INCLUDED_BMESH_H
#ifdef __cplusplus
extern "C" {
#endif

#include <lobi/inttypes.h>

/* data storage type */
#define BMESH_DS_ASCII			'A'
#define BMESH_DS_BINARY			'B'

/* content descriptor bits */
#define BMESH_CD_VERTEX_DATA	(1<<0)
#define BMESH_CD_NORMAL_DATA	(1<<1)
#define BMESH_CD_TRIANGLE_DATA	(1<<2)

/* header descriptor bits */
#define BMESH_HD_POINTS			(1<<0)
#define BMESH_HD_TRIANGLES		(1<<1)


/* The actual mesh structure as returned by the read() functions */
struct bmesh_t
{
	int	content_descriptor;				/* BMESH_CD_XXX */
	int header_descriptor;				/* BMESH_HD_XXX */
	int data_storage_type;				/* BMESH_DS_XXX */
	
	/* content data */
	float*		vertex_data;
	float*		normal_data;
	uint32_t*	triangle_data;
	
	/* header descriptor data */
	int num_points;
	int num_triangles;
};

/*
 * error handling
 */

extern int bmesh_errno;

#define BMESH_E_NOERROR			0
#define BMESH_E_INVALID_MAGIC	1
#define BMESH_E_HEADER_CORRUPT	2
#define BMESH_E_DATA_CORRUPT	3
#define BMESH_E_INVALID_PARAM	4
#define BMESH_E_NOT_IMPLEMENTED	5

/*
 * functions
 */

struct bmesh_t* bmesh_sread(const char* data);
int bmesh_free(struct bmesh_t* mesh);

#ifdef __cplusplus
}
#endif
#endif /* INCUDED_BMESH_H */

